package com.water.app.Config;


import org.springframework.ai.chat.memory.repository.jdbc.JdbcChatMemoryRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

@Configuration
public class MySqlMemoryRepositoryConfig {

    @Value("${spring.datasource.url}")
    private String mysqlUrl;

    @Value("${spring.datasource.username}")
    private String username;

    @Value("${spring.datasource.password}")
    private String password;

    @Value("${spring.datasource.driver-class-name}")
    private String driverName;

    @Bean
    public DriverManagerDataSource myDriverMangerDataSource(){
        DriverManagerDataSource dataSource=new DriverManagerDataSource();
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        dataSource.setUrl(mysqlUrl);
        dataSource.setDriverClassName(driverName);
        return dataSource;
    }

    @Bean
    public JdbcTemplate myJdbcTemplate(DriverManagerDataSource dataSource){
        return new JdbcTemplate(dataSource);
    }

    @Bean
    public JdbcChatMemoryRepository myJdbcChatMemoryRepository(JdbcTemplate jdbcTemplate){
        return JdbcChatMemoryRepository.builder()
                .jdbcTemplate(jdbcTemplate)
                .build();
    }


}
